package com.punai.web.controller.system;

import com.punai.common.core.controller.BaseController;
import com.punai.common.core.domain.AjaxResult;
import com.punai.common.core.domain.entity.SysDept;
import com.punai.common.core.page.TableDataInfo;
import com.punai.system.service.SysDeptLinkDeptService;
import com.punai.web.controller.from.req.DeptLinkReq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/deptlink")
public class SysDeptLinkDeptController extends BaseController {

    @Autowired
    private SysDeptLinkDeptService deptLinkDeptService;


    @GetMapping("/getDeptLinkList")
    public TableDataInfo getDeptLinkList() {
        List<SysDept> sysDepts = deptLinkDeptService.getDeptLinkList();
        return getDataTable(sysDepts);
    }

    @GetMapping("/getDeptSelectTree/{deptId}")
    public AjaxResult getDeptSelectTree(@PathVariable Long deptId) {
        List<SysDept> sysDepts = deptLinkDeptService.getDeptSelectTree(deptId);
        return AjaxResult.success(sysDepts);
    }

    @GetMapping("/getDeptLinkTree/{deptId}")
    public AjaxResult getDeptLinkTree(@PathVariable Long deptId) {
        List<Long> checkedDeptIds = deptLinkDeptService.getDeptLinkTree(deptId);
        return AjaxResult.success(checkedDeptIds);
    }

    @PostMapping("/setLinkIds")
    public AjaxResult setLinkIds(@RequestBody DeptLinkReq req) {
        deptLinkDeptService.setLinkIds(req.getDeptId(),req.getLinkDeptIds());
        return AjaxResult.success();
    }

}
